package com.khalil.kkadmin.web;

import com.khalil.kkadmin.common.web.RespResult;
import com.khalil.kkadmin.system.menu.SysMenu;
import com.khalil.kkadmin.system.menu.SysMenuService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys/menu")
public class SysMenuController {

    private final SysMenuService sysMenuService;


    public SysMenuController(SysMenuService sysMenuService) {
        this.sysMenuService = sysMenuService;
    }

    @GetMapping("/listTree")
    public RespResult<List<SysMenu>> listTree() {
        return RespResult.ok(sysMenuService.getTree());
    }

    @GetMapping("/{id}")
    public RespResult<SysMenu> get(@PathVariable("id") Integer id) {
        return RespResult.ok(sysMenuService.get(id));
    }

    @PostMapping("")
    public RespResult<SysMenu> saveOrUpdate(@RequestBody SysMenu sysMenu) {
        return RespResult.ok(sysMenuService.saveOrUpdate(sysMenu));
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id) {
        sysMenuService.delete(id);
    }
}